/*
 * File.qt.cpp
 *
 *  Created on: 19.02.2011
 *      Author: Kevin Mueller
 */

#include "QtFile.h"

#include <QFile>
#include <QtCore>

namespace opennav {

QtFile::QtFile(const QString& name, QObject* parent){
	file = new QFile(name, parent);
	file->open(QIODevice::ReadOnly | QIODevice::Unbuffered);
}

QtFile::~QtFile(){
	file->close();
	delete file;
}

bool QtFile::seek(int32_t pos) {
	return file->seek(static_cast<qint64>(pos));
}

bool QtFile::read(void* buffer, int32_t size, int32_t& read_bytes) {
	read_bytes = file->read(static_cast<char*>(buffer), size);
	return read_bytes>=0;
}

bool QtFile::close() {
	file->close();
	return true;
}

bool QtFile::size(int32_t& size) {
	size = static_cast<int32_t>(file->size());
	return size>=0;
}

bool QtFile::position(int32_t& position) {
	position = (int32_t)file->pos();
	return true;
}

bool QtFile::exists() const{
	return file->exists();
}

bool QtFile::readable() const{
	return (file->permissions() & QFile::ReadUser);
}
}
